// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

const { ccclass, property } = cc._decorator;
// var SKINS = ["jingzhang", "shudaizi"];
var SKINS = ["mecha_1502b", "skin_a", "skin_b", "skin_c"];
@ccclass
export default class NewClass extends cc.Component {

    @property(dragonBones.ArmatureDisplay)
    targetArmature: dragonBones.ArmatureDisplay = null;

    @property(dragonBones.ArmatureDisplay)
    skinArmature: dragonBones.ArmatureDisplay = null;

    private _skinIndex: number = 0;

    onLoad() {
        // load all skin data
        // for (let i = 1; i < SKINS.length; i++) {
        //     this.skinArmature.armatureName = SKINS[i];
        // }
    }

    replaceSkin() {
        let skinName = SKINS[++this._skinIndex % SKINS.length];
        let factory = dragonBones.CCFactory.getInstance();
        let skinData = factory.getArmatureData(skinName).defaultSkin;
        // factory.replaceSkin(this.targetArmature.armature(), skinData, false, ["weapon_l", "weapon_r"]);
        factory.replaceSkin(this.targetArmature.armature(), skinData, false);
    }

    replaceAnimation() {
        // let skinName = SKINS[++this._skinIndex % SKINS.length];
        let factory = dragonBones.CCFactory.getInstance();
        let skinData = factory.getArmatureData("mecha_1502b");
        // factory.replaceSkin(this.targetArmature.armature(), skinData, false, ["weapon_l", "weapon_r"]);
        factory.replaceAnimation(this.skinArmature.armature(), skinData);
        this.skinArmature.playAnimation("walk", 0);
    }

    mixAnimation() {
        let armature = this.targetArmature.armature();
        let state = armature.animation.fadeIn("attack_01", -1, 0, 0, "attackGroup");
        state.resetToPose = false;
        state.weight = 1;

        state = armature.animation.fadeIn("walk", -1, 0, 0, "walkGroup");
        state.resetToPose = false;
        state.weight = 1;

        // state.addBoneMask("outerleg_upper");
        // state.addBoneMask("innerleg_upper");
    }
}
